<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html >
    <head>
        <meta charset="utf-8">
        <title>
            添加积分
        </title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="../../../backstage/css/x-admin.css" media="all">
    </head>
    <body>
        <div class="z-body">
            <form class="layui-form">
                <div class="layui-form-item">
                    <label for="userId" class="layui-form-label">
                        <span class="x-red">*</span>用户ID
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="userId" name="userId" required="" lay-verify="required" autocomplete="off"  class="layui-input"
                               maxlength="10" onkeyup="value=this.value.replace(/\D+/g,'')" disabled="disabled">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="inputCredit" class="layui-form-label">
                        <span class="x-red">*</span>积分
                    </label>
                    <div class="layui-input-inline">
                        <input type="number" id="inputCredit" name="inputCredit" required=""  lay-verify="required" autocomplete="off"
                               class="layui-input" oninput = "if(value>99999)value=99999;value=value.replace(/[^\d]/g,'')">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">
                    </label>
                    <input type="button" id="add" value="添加" class="layui-btn" lay-filter="save" lay-submit="add">

                    </input>
                </div>
            </form>
        </div>
        <script src="../../../backstage/lib/layui/layui.js" charset="utf-8"></script>
        <script src="../../../backstage/js/x-layui.js" charset="utf-8"></script>
        <script>
            layui.use(['form','layer'], function() {
                $ = layui.jquery;
                var form = layui.form();
                layer = layui.layer;


                form.verify({
                    inputCredit: function (value) {
                        if (value.length <= 0) {
                            return '积分值不能为空';
                        }
                    }

                });
                $(document).ready(function () {
                    //获取传递过来的localStorage
                    var id = window.localStorage.getItem('msg');
                    $("#userId").val(id);
                    //积分添加
                    $("#add").click(function () {
//                    var userId = $.trim($("#userId").val());
                        var inputCredit = $.trim($("#inputCredit").val());
                        console.log(id);
                        console.log(inputCredit);

                        $.ajax({
                            type: 'POST',
                            url: '/credit/add',
                            dataType: "json",
                            data: {uid: id, inputCredit: inputCredit},
                            error: function () {
                                alert("失败");
                            },
                            success: function (data) {
                                if (data.message == "添加成功") {
                                    alert("添加成功！");
                                } else if (data.message == "用户不存在") {
                                    alert("用户不存在，无法添加");
                                }
                                location.reload();
                            }
                        });
                    });
                });
            });
        </script> 
    </body>
</html>